﻿using DAL;
using DAL.DataTransferObject;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Windows.Forms;

namespace BAL
{
    public class HangHoaBAO
    {
        public static HangHoaDAO hhDAO = new HangHoaDAO();
        public void HangHoa_AddNew(HangHoa hh)
        {
            NhaPhanPhoiBAO nppBAO = new NhaPhanPhoiBAO();
            foreach(NhaPhanPhoi item in nppBAO.NPP_GetData())
                if (item.MaNPP==hh.maNPP&&item.NgayBatDauHD==item.NgayKetThucHD)
                {
                    MessageBox.Show("Nhà phân phối mã {0} không còn trong danh sách nữa !",item.MaNPP);
                    return;
                }
            hhDAO.HangHoa_AddNew(hh);
        }
        public void HangHoa_Update(HangHoa hh)
        {
            hhDAO.HangHoa_Update(hh);
        }
        public void HangHoa_Delete(HangHoa hh)
        {
            hh.soLuong = 0;
            hhDAO.HangHoa_Update(hh);
        }
        public List<HangHoa> HangHoa_GetData()
        {
            return hhDAO.HangHoa_GetData();
        }
        public bool HangHoa_CheckId(string a)
        {
            return hhDAO.HangHoa_CheckId(a);
        }
        public List<HangHoa> HangHoa_SearchName(string a)
        {
            return hhDAO.HangHoa_SearchName(a);
        }
        public List<HangHoa> HangHoa_CheckExp()
        {
            return hhDAO.HangHoa_CheckExp();
        }
        public DataTable SelectNameHangHoa(string maHang)
        {
            return hhDAO.SelectNameHangHoa(maHang);
        }

        public HangHoa GetHangHoaObj(string maHang)
        {
            return hhDAO.GetHangHoaObj(maHang);
        }
        public SqlDataReader HangHoa_Get(string a, string b)
        {
            return hhDAO.HangHoa_Get(a, b);
        }
        public SqlDataReader autoComplete()
        {
            return hhDAO.autoComplete();
        }

        public DataView SelectAllViewHangHoa()
        {
            return hhDAO.SelectAllViewHangHoa();
        }
    }
}
